var UId = getParameter("UId");
var now = new Date();
$(function() {
	charts(now);
});
function charts(now) {
	var urlStr = serverPath + "/app/doctor/diabetes/mealView.do"; 
    var jsonStr ='{method:"getMealTable",uid:"' + UId + '",date:"' + now.format("yyyy-MM-dd") + '",day:"1"}';
    UseAjax(urlStr, jsonStr, document.cookie, rt, '1');
}
function rt(data) {
	var datas = new Array();
	var wi = data.records;
	if(wi.length > 0){
		datas=[isnull(wi[0].breakfast),isnull(wi[0].lunch),isnull(wi[0].dinner),isnull(wi[0].snack)];
	}
    var target =  data.target;
	var dates = [ "早餐","午餐","晚餐","加餐" ];
	$('#container').highcharts(
			{

				title : {
					text : ''
				},
				subtitle : {
					text :  now.format("yyyy-MM-dd")
				},
				xAxis : {
					
					  labels: { 
						  },
					 
					gridLineWidth : 1,
					gridLineDashStyle : 'Dash',// 样式 虚线

					categories : dates
				},
				yAxis : {
					min : 0, // 固定列最小值
					max : 3000,
					title : {
						align: 'high',
		                offset: 10,
		                text: '千卡',
		                rotation: 0,
		                y: -10	
					},labels : {
						formatter : function() {
							return "" + this.value ;
						}
					} ,plotLines: [{ 
						value: target,//標示線 
						width: 1, 
						color:'#808080',
						label:{
						     text:target,     //标签的内容
						     align:'left',                //标签的水平位置，水平居左,默认是水平居中center
						     x:-40                         //标签相对于被定位的位置水平偏移的像素，重新定位，水平居左10px
						    }
						  }]
					,
				},
				tooltip : {
					formatter : function() {
					}
				},
				plotOptions : {
					line : {
						dataLabels : {
							enabled : true
						},
						enableMouseTracking : false
					}
				},
				credits : {
					enabled : false
				},
				legend : {
					enabled : false
				},
				series : [ {
					pointPadding : 0,// 数据点之间的距离值
					groupPadding : 0,// 分组之间的距离值
					name : null,
					data : datas
			
				} ]
			});
}

$(function() {
	// swipe 的dome
	$("#container").swipe(
			{
				swipeLeft : function(event, direction, distance, duration,
						fingerCount) {

					now = getNextDay(now, 1);
					charts(now);
				},
				swipeRight : function(event, direction, distance, duration,
						fingerCount) {
					now = getLastDay(now, 1);
					charts(now);
				},
			});

});
function isnull(value) {
	if(value == null || value == "" || value == undefined){
		return null;
	}else{
		return Number(value);
	}
}